//
//  BasedoorAir.m
//  DrawBezierDemo
//
//  Created by wulanzhou on 16/5/16.
//  Copyright © 2016年 wulanzhou. All rights reserved.
//

#import "BasedoorAir.h"
#import "UIColor+CZExtend.h"

@implementation BasedoorAir

/**
 *  取得指标等级颜色值集合
 *
 *  @return
 */
- (NSArray <BezierdoorAngle*> *)GetIndexLevelColors{

    NSMutableArray *colors=[NSMutableArray arrayWithCapacity:0];
    
    
    BezierdoorAngle *mod=[self levelWithStartPM:0 endPM:11 prevAngle:-150];
    if (mod) {
        [colors addObject:mod];
    }
    
    
    mod=[self levelWithStartPM:12 endPM:23 prevAngle:[self GetLastAngleWithSource:colors]];
    if (mod) {
        [colors addObject:mod];
    }
    
    mod=[self levelWithStartPM:24 endPM:35 prevAngle:[self GetLastAngleWithSource:colors]];
    if (mod) {
        [colors addObject:mod];
    }
    
    mod=[self levelWithStartPM:36 endPM:41 prevAngle:[self GetLastAngleWithSource:colors]];
    if (mod) {
        [colors addObject:mod];
    }
    
    mod=[self levelWithStartPM:42 endPM:47 prevAngle:[self GetLastAngleWithSource:colors]];
    if (mod) {
        [colors addObject:mod];
    }
    
    mod=[self levelWithStartPM:48 endPM:53 prevAngle:[self GetLastAngleWithSource:colors]];
    if (mod) {
        [colors addObject:mod];
    }
    
    mod=[self levelWithStartPM:54 endPM:58 prevAngle:[self GetLastAngleWithSource:colors]];
    if (mod) {
        [colors addObject:mod];
    }
    
    mod=[self levelWithStartPM:59 endPM:64 prevAngle:[self GetLastAngleWithSource:colors]];
    if (mod) {
        [colors addObject:mod];
    }
    
    mod=[self levelWithStartPM:65 endPM:70 prevAngle:[self GetLastAngleWithSource:colors]];
    if (mod) {
        [colors addObject:mod];
    }
    
    //NSLog(@"colors count=%d",[colors count]);

    return colors;
}

#pragma mark -私有方法
/**
 *  取得pm值对应的角度
 */
- (CGFloat)degressWithPM:(NSInteger)p{
    //表示一点对应的角应(70表示最大的pm,60表示对应一半弧度)
    CGFloat dotDegress=60/(70/2.0);
    
    if (p>=0&&p<=35){
        
        return -150.0+p*dotDegress;
    }
    
    return -90+(p-(70/2.0))*dotDegress;
}

- (BezierdoorAngle *)levelWithStartPM:(NSInteger)startPM endPM:(NSInteger)endPM prevAngle:(CGFloat)angle{
    
    //if (self.pm>=startPM&&self.pm<=endPM) {
    
    
    UIColor *levelColor=[self colorWithStartPM:startPM endPM:endPM];
    
    if (levelColor) {
        BezierdoorAngle *mod=[[BezierdoorAngle alloc] init];
        mod.bezierColor=levelColor;
        mod.startAngle=angle;
        
        if (self.pm>endPM) {
            mod.endAngle=[self degressWithPM:endPM];
            
        }else{
            mod.endAngle=[self degressWithPM:self.pm];
        }
        
        return mod;
    }
    
    return nil;

}

- (UIColor *)colorWithStartPM:(NSInteger)startPM endPM:(NSInteger)endPM{
    
    if (startPM==0&&endPM==11&&((self.pm>=startPM&&self.pm<=endPM)||self.pm>endPM)) {
        return UIColorMakeRGB(146,251,162);
    }

    if (startPM==12&&endPM==23&&((self.pm>=startPM&&self.pm<=endPM)||self.pm>endPM)){
        return UIColorMakeRGB(0,250,57);
    }
    if (startPM==24&&endPM==35&&((self.pm>=startPM&&self.pm<=endPM)||self.pm>endPM)){
        
        return UIColorMakeRGB(0,207,46);
    }
    if (startPM==36&&endPM==41&&((self.pm>=startPM&&self.pm<=endPM)||self.pm>endPM)){
        
        return UIColorMakeRGB(255,252,66);
    }
    if (startPM==42&&endPM==47&&((self.pm>=startPM&&self.pm<=endPM)||self.pm>endPM)){
        
        return UIColorMakeRGB(255,207,56);
    }
    if (startPM==48&&endPM==53&&((self.pm>=startPM&&self.pm<=endPM)||self.pm>endPM)){
        return UIColorMakeRGB(255,154,46);
    }
    if (startPM==54&&endPM==58&&((self.pm>=startPM&&self.pm<=endPM)||self.pm>endPM)){
        return UIColorMakeRGB(255,100,104);
    }
    
    if (startPM==59&&endPM==64&&((self.pm>=startPM&&self.pm<=endPM)||self.pm>endPM)){
        
        return UIColorMakeRGB(255,35,31);
    }
    if (startPM==65&&endPM==70&&(self.pm>=startPM&&self.pm<=endPM)){
        
        return UIColorMakeRGB(159,16,13);
    }
    return nil;
}

- (CGFloat)GetLastAngleWithSource:(NSArray *)source{

    if (source&&[source count]>0) {
        
        BezierdoorAngle *lastModel=[source lastObject];
        return lastModel.endAngle-1;
    }
    return -150.0;
}

@end
